package com.codi.bus.core.service.impl;

import com.codi.bus.core.dao.UserMsgDao;
import com.codi.bus.core.domain.UserMsg;
import com.codi.bus.core.service.MessageService;
import com.codi.bus.core.service.UserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by asus on 2018/4/13.
 */
@Service("userMessageService")
@Transactional
public class UserMessageServiceImpl implements UserMessageService {
    @Autowired
    private UserMsgDao userMsgDao;

    @Autowired
    private MessageService messageService;

    @Override
    public Integer getCount(Long userId, Integer msgType){
        Integer i = 0;
        if (msgType != -1){
            i = userMsgDao.selectMessageCount(userId, msgType,null);
        }else {
            i = userMsgDao.selectMessageCount(userId, null,null);
        }
        return i;
    }

    @Override
    public Integer getSysMessageCount(Long userId) {
        return messageService.getUserSysMessageCounts(userId);
    }

    @Override
    public Page<UserMsg> getMessage(Long userId, Integer msgType, Integer titleType, Pageable pageable){
        Page<UserMsg> userMsgs = userMsgDao.selectMessage(userId, msgType, titleType, pageable,null);
        userMsgDao.updateMessageState(userId, msgType,null);
        return userMsgs;
    }
}
